﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.IO;

namespace PcBackgroundMgr.Controls
{
    /// <summary>
    /// SelectButton.xaml 的交互逻辑
    /// </summary>
    public partial class SelectButton : SelectButtonBase
    {
        public SelectButton()
        {
            InitializeComponent();
        }

    }
    [System.ComponentModel.DesignTimeVisible(false)]
    public class SelectButtonBase : Button
    {
        public enum SelectTypeEnum
        {
            All,Pictrue,Video,Music,Document
        }

        public SelectTypeEnum SelectType
        {
            get { return (SelectTypeEnum)GetValue(SelectTypeProperty); }
            set { SetValue(SelectTypeProperty, value); }
        }

        // Using a DependencyProperty as the backing store for SelectType.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SelectTypeProperty =
            DependencyProperty.Register("SelectType", typeof(SelectTypeEnum),
            typeof(SelectButtonBase), 
            new UIPropertyMetadata(SelectTypeEnum.All));

        protected override void OnClick()
        {
            if (this.Command != null)
            {
                base.OnClick();
                return;
            }

            #region 打开本地资源

            OpenFileDialog openFileDialog = new OpenFileDialog();

            //初始化打开为电脑桌面路径
            switch (SelectType)
            {
                case SelectTypeEnum.Pictrue:
                    openFileDialog.Filter = "图像文件|*.png;*.jpg;*.bmp;*gif|所有文件|*.*";
                    break;
                case SelectTypeEnum.Video:
                    openFileDialog.Filter = "视频文件|*.avi;*.mpg;*.mp4;*flv|所有文件|*.*";
                    break;
                default:
                    openFileDialog.Filter = "所有文件|*.*";
                    break;
            }

            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;

            if (openFileDialog.ShowDialog() == true)
            {
                FilePath = openFileDialog.FileName;//获得选择的文件路径
                FileName = System.IO.Path.GetFileName(FilePath);//获取文件名
            }

            #endregion 打开本地资源

        }

        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string),
            typeof(SelectButtonBase), new UIPropertyMetadata("选择"));

        public double StrokeThickness
        {
            get { return (double)GetValue(StrokeThicknessProperty); }
            set { SetValue(StrokeThicknessProperty, value); }
        }

        // Using a DependencyProperty as the backing store for StrokeThickness.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty StrokeThicknessProperty =
            DependencyProperty.Register("StrokeThickness", typeof(double),
            typeof(SelectButtonBase));


        public Brush ShadeBrush
        {
            get { return (Brush)GetValue(ShadeBrushProperty); }
            set { SetValue(ShadeBrushProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ShadeBrush.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ShadeBrushProperty =
            DependencyProperty.Register("ShadeBrush", typeof(Brush),
            typeof(SelectButtonBase), new UIPropertyMetadata(new SolidColorBrush(Color.FromArgb(0x99,0,0,0))));

        public DoubleCollection StrokeDashArray
        {
            get { return (DoubleCollection)GetValue(StrokeDashArrayProperty); }
            set { SetValue(StrokeDashArrayProperty, value); }
        }

        // Using a DependencyProperty as the backing store for StrokeDashArray.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty StrokeDashArrayProperty =
            DependencyProperty.Register("StrokeDashArray", typeof(DoubleCollection),
            typeof(SelectButtonBase));

        public string FileName
        {
            get { return (string)GetValue(FileNameProperty); }
            set { SetValue(FileNameProperty, value); }
        }

        // Using a DependencyProperty as the backing store for FileName.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FileNameProperty =
            DependencyProperty.Register("FileName", typeof(string),
            typeof(SelectButtonBase), new UIPropertyMetadata(""));

        public string FilePath
        {
            get { return (string)GetValue(FilePathProperty); }
            set { SetValue(FilePathProperty, value); }
        }

        // Using a DependencyProperty as the backing store for FilePath.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FilePathProperty =
            DependencyProperty.Register("FilePath", typeof(string),
            typeof(SelectButtonBase), new UIPropertyMetadata(""));

        /************************************************************************/
        /* 
			{ ".3gp", "video/3gpp" },
			{ ".apk", "application/vnd.android.package-archive" },
			{ ".asf", "video/x-ms-asf" },
			{ ".avi", "video/x-msvideo" },
			{ ".bin", "application/octet-stream" },
			{ ".bmp", "image/bmp" },
			{ ".c", "text/plain" },
			{ ".class", "application/octet-stream" },
			{ ".conf", "text/plain" },
			{ ".cpp", "text/plain" },
			{ ".doc", "application/msword" },
			{ ".docx",
					"application/vnd.openxmlformats-officedocument.wordprocessingml.document" },
			{ ".xls", "application/vnd.ms-excel" },
			{ ".xlsx",
					"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" },
			{ ".exe", "application/octet-stream" },
			{ ".gif", "image/gif" },
			{ ".gtar", "application/x-gtar" },
			{ ".gz", "application/x-gzip" },
			{ ".h", "text/plain" },
			{ ".htm", "text/html" },
			{ ".html", "text/html" },
			{ ".jar", "application/java-archive" },
			{ ".java", "text/plain" },
			{ ".jpeg", "image/jpeg" },
			{ ".jpg", "image/jpeg" },
			{ ".js", "application/x-javascript" },
			{ ".log", "text/plain" },
			{ ".m3u", "audio/x-mpegurl" },
			{ ".m4a", "audio/mp4a-latm" },
			{ ".m4b", "audio/mp4a-latm" },
			{ ".m4p", "audio/mp4a-latm" },
			{ ".m4u", "video/vnd.mpegurl" },
			{ ".m4v", "video/x-m4v" },
			{ ".mov", "video/quicktime" },
			{ ".mp2", "audio/x-mpeg" },
			{ ".mp3", "audio/x-mpeg" },
			{ ".mp4", "video/mp4" },
			{ ".mpc", "application/vnd.mpohun.certificate" },
			{ ".mpe", "video/mpeg" },
			{ ".mpeg", "video/mpeg" },
			{ ".mpg", "video/mpeg" },
			{ ".mpg4", "video/mp4" },
			{ ".mpga", "audio/mpeg" },
			{ ".msg", "application/vnd.ms-outlook" },
			{ ".ogg", "audio/ogg" },
			{ ".pdf", "application/pdf" },
			{ ".png", "image/png" },
			{ ".pps", "application/vnd.ms-powerpoint" },
			{ ".ppt", "application/vnd.ms-powerpoint" },
			{ ".pptx",
					"application/vnd.openxmlformats-officedocument.presentationml.presentation" },
			{ ".prop", "text/plain" }, { ".rc", "text/plain" },
			{ ".rmvb", "audio/x-pn-realaudio" }, { ".rtf", "application/rtf" },
			{ ".sh", "text/plain" }, { ".tar", "application/x-tar" },
			{ ".tgz", "application/x-compressed" }, { ".txt", "text/plain" },
			{ ".wav", "audio/x-wav" }, { ".wma", "audio/x-ms-wma" },
			{ ".wmv", "audio/x-ms-wmv" },
			{ ".wps", "application/vnd.ms-works" }, { ".xml", "text/plain" },
			{ ".z", "application/x-compress" },
			{ ".zip", "application/x-zip-compressed" }, { "", } };                                                                     */
        /************************************************************************/

    }
}
